package cn.wolfcode.car.business.service.impl;

import cn.wolfcode.car.business.domain.GoodsStore;
import cn.wolfcode.car.business.domain.Store;
import cn.wolfcode.car.business.domain.Goods;
import cn.wolfcode.car.business.domain.StockBillItem;
import cn.wolfcode.car.business.mapper.GoodsStoreMapper;
import cn.wolfcode.car.business.mapper.StockBillItemMapper;
import cn.wolfcode.car.business.mapper.StoreMapper;
import cn.wolfcode.car.business.query.StockBillItemQuery;
import cn.wolfcode.car.business.service.IStockBillItemService;
import cn.wolfcode.car.business.service.IStoreService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.exception.BusinessException;
import cn.wolfcode.car.common.util.Convert;
import cn.wolfcode.car.shiro.ShiroUtils;
import com.github.pagehelper.PageHelper;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class StockBillItemServiceImpl implements IStockBillItemService {

    @Autowired
    private StockBillItemMapper stockBillItemMapper;



    @Override
    public TablePageInfo<StockBillItem> query(StockBillItemQuery qo) {
        PageHelper.startPage(qo.getPageNum(), qo.getPageSize());
        return new TablePageInfo<StockBillItem>(stockBillItemMapper.selectForList(qo));
    }


    @Override
    public void save(StockBillItem stockBillItem) {
        // 添加服务
        stockBillItemMapper.insert(stockBillItem);
    }

    @Override
    public StockBillItem get(Long id) {
        return stockBillItemMapper.selectByPrimaryKey(id);
    }


    @Override
    public void update(StockBillItem stockBillItem) {
        stockBillItemMapper.updateByPrimaryKey(stockBillItem);
    }

    @Override
    public void removeBillItem(Long id) {
        stockBillItemMapper.deleteByBillId(id);
    }

    @Override
    public List<StockBillItem> list() {
        return stockBillItemMapper.selectAll();
    }

    @Override
    public void deleteBatch(String ids) {
        Long[] dictIds = Convert.toLongArray(ids);
        for (Long dictId : dictIds) {
            stockBillItemMapper.deleteByPrimaryKey(dictId);
        }
    }

    @Override
    public void updateAmounts(List<Goods> list) {
        for (Goods goods : list) {
            stockBillItemMapper.updateAmounts(goods.getId(),goods.getAmounts());
        }
    }

}
